from celery_tasks.main import celery_app
from django.core.mail import send_mail
import logging
logger = logging.getLogger('django')
@celery_app.task(name='celery_send_email')
def celery_send_email(subject, message, from_email, recipient_list, html_message):
    """
    发送邮件
    :param subject: 邮件标题
    :param message: 邮件正文
    :param from_email: 发件人
    :param recipient_list: 收件人列表
    :param html_message: HTML格式的邮件正文
    :return: None
    """
    try:
        send_mail(subject=subject,
                   message=message, 
                   from_email=from_email, 
                   recipient_list=recipient_list, 
                   html_message=html_message)
    except Exception as e:
        logger.error('发送邮件失败, 收件人: %s, 异常信息: %s' % (recipient_list, e))
        raise e